<template>
	<view class="index" style="height: 100vh;">
		<web-view :src="weburl + 'html5/'" bindmessage="bindmessage" ></web-view>
	</view>
</template>

<script>
	// 获取应用实例
	const app = getApp();
	let request = require('../../utils/require');
    export default {
        data() {
            return {
                weburl:'',
                is_wxminiapp:'',
				imgUrl: app.globalData.imgUrl,
				shareData:""
            }
        },
		//用户点击右上角分享朋友圈
		onShareTimeline: function() {
			var that = this;
			return {
				title: that.kefulist.name,
				query: {
					key: '/pages/main/index'
				},
				imageUrl: that.kefulist.file_path
			};
		},
		// 注意：只有定义了此事件处理函数，右上角菜单才会显示“转发”按钮
		onShareAppMessage() {
			return {
				// 用Promise延时一下，避免bindmessage还未执行完毕，就唤起转发
				promise: new Promise(resolve => {
					setTimeout(() => {
						resolve({
							title: this.data.shareData.title,
							path: `/pages/index/index${this.data.shareData.path}`,//这个path是来自H5页面的传参路径
						})
					}, 100)
				})
			}
		},
		//分享
		// onShareAppMessage(){
		// 	var that = this;
		// 	var thisUserInfo = uni.getStorageSync('userInfo');
		// 	var shareObj = {
		// 		title: that.kefulist.title,
		// 		desc: that.kefulist.desc,
		// 		// 默认是小程序的名称(可以写SOGO express集运等)
		// 		path: '/pages/main/index?scene=uid%3A' + thisUserInfo.user_id,
		// 		// thisUserInfo.user_id
		// 		// scene: "uid%3A15027"
		// 		// 默认是当前页面，必须是以‘/’开头的完整路径
		// 		imageUrl: that.kefulist.file_path,
		// 		//自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
		// 		success: function(res) {
		// 			// 转发成功之后的回调
		// 			if (res.errMsg == 'shareAppMessage:ok') {
		// 			}
		// 		},
		// 		fail: function() {
		// 			// 转发失败之后的回调
		// 			if (res.errMsg == 'shareAppMessage:fail cancel') {
		// 				// 用户取消转发
		// 			} else {
		// 				if (res.errMsg == 'shareAppMessage:fail') {
		// 				}
		// 			}
		// 		}
		// 	};
		// 	return shareObj;
		// },
		onShow() {
		},
        onLoad(res) {
			this.kefulistFun();
        },
		onReady(){
            uni.setNavigationBarTitle({
                title:this.title
            })
        },
		methods:{
			bindmessage(d) {
				if (d && d.detail && d.detail.data) {
					//console.log('H5传过来的最新信息', JSON.stringify(d.detail.data.slice(-1)[0], null, 2));
					this.shareData = d.detail.data.slice(-1)[0];//因为bindmessage推送过来的数据是push的形式，所以最新的数据是在最后
				}
			},   
			kefulistFun() {
				var that = this;
				var data = {
					token: uni.getStorageSync('token')
				};
				request.post(`index.php?s=/api/page/service&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
					if (res.data.code == 1) {
						that.weburl = res.data.data.copyright.other_url
						that.kefulist= res.data.data.values
						that.is_wxminiapp = res.data.data.copyright.is_wxminiapp		
						uni.setStorageSync('setting', res.data.data.values);
						uni.setStorageSync('paytype', res.data.data.paytype);
						uni.setStorageSync('copyright', res.data.data.copyright);
						uni.setStorageSync('userclient', res.data.data.userclient);
						uni.setStorageSync('weight_mode', res.data.data.values.weight_mode);
						uni.setStorageSync('price_mode', res.data.data.values.price_mode);
						uni.setStorageSync('appname', res.data.data.values.name);
						uni.setStorageSync('is_categorysearch', res.data.data.values.is_categorysearch);
						uni.setStorageSync('address_setting', res.data.data.values.address_setting);
						uni.setStorageSync('menu_type', res.data.data.values.menu_type);
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						});
					}
				});
			},
		}
    }
</script>
